<?
	require_once "../../_func/__Global.php";
	require_once "../../_func/__Local.php";
	require_once "../../_func/__MysqlFunc.php";
	require_once "../../_func/_BoardFunc.php";

	$db = new MySQLConnection();
	$db->connect();

if($_POST['act'] == 'delete'){
	for($i=0;$i<sizeof($_POST['chkbox']);$i++){
		if($_POST['chkbox'][$i]> 0){
			$sql = "update BRD_MEMO set snd_del='Y' where memo_idx='".$_POST['chkbox'][$i]."'";
			$sth  = $db->query($sql);
		}
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>받은쪽지 :: 농협전북지부 ERP시스템 ::</title>
<link href="/css/layout.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="/js/tab.js"></script>
</head>
<script language="javascript">
	function goDelete(){
		var F = document.listForm
		var lenchk = 0;
		len = document.getElementsByName("chkbox[]").length

		for(i=1;i<len;i++){
			if(document.getElementsByName("chkbox[]")[i].checked){
				lenchk = 1;
				break;
			}
		}
		if(lenchk == 0){
			alert('삭제할 메시지를 선택해 주세요');
			return false;
		}
		if(!confirm('선택된 메시지를 삭제 하시겠습니까?'))
			return false;

		F.act.value="delete";
		F.submit();
	}
	function SetCheck(){
		var setcheck = false;
		if(document.getElementsByName("chkbox[]")[0].checked){
			setcheck = true;
		}
		for(i=1;i<document.getElementsByName("chkbox[]").length;i++){
			document.getElementsByName("chkbox[]")[i].checked = setcheck
		}
	}
</script>
<body>
<div id="wrap">
	<!-- header start -->
	<? include("../_layout/head.inc"); ?>
	<!-- header end -->

<!-- container start -->
	<div id="container">


	<div id="b1">
    <div class="subtit">
        	<p class="subtt14"><span>쪽지 > 받은쪽지</span></p>
		</div>

    <div class="contents">
		<input type="hidden" name="stype" id="stype" value="group" />
		<ul class="tab_input">
			<li class="tab_left">
            	<a href="msg_recv.html" onClick="MM_showHideLayers('b1','','show','b2','','hide');document.getElementById('stype').value='individual';">받은쪽지</a>
			</li>
			<li class="tab_right on"> <a href="msg_snd.html">보낸쪽지</a></li>
		</ul>
        <div class="sendMsg"><a href="javascript:;" onClick="window.open('memo_write.html','','width=400,height=400,scrollbars=no');">
            	<span class="btn_msg"></span></a>
		</div>
		<form name="listForm" method="post">
			<input type="hidden" name="act" value="">
		<table cellpadding="0" cellspacing="1" border="0" class="msgTable">
        	<colgroup>
             <col width="3%" />
            <col width="4%" />
            <col width="*" />
            <col width="100" />
            <col width="150" />
            <col width="150" />
            </colgroup>
            	<tr>
		<th><input type="checkbox" id="chkbox[]" name="chkbox[]"  title="전체삭제" value="" onclick="SetCheck();"/></th>
		<th>번호</th>
		<th>내용</th>
		<th>받는사람</th>
		<th>보낸시간</th>
		<th>수신확인</th>
		</tr>
<?
		if ($page < 1)
			$page = 1;
            	$basic_param = array(
		'page'		=> $page,
		'query'		=> $query,
		);
		$sql = "select	count(memo_idx) from BRD_MEMO  where snd_del != 'Y' and snd_idx ='".$session->getString("userno")."'";
		$sth  = $db->query($sql);

		$list = &$db->queryList($sql);
            	$totalcount =  mysql_result($sth,0,0);
            	$pagesize 		= 9;
		$pagelistsize 	= 10;
		$totalpage 	= ceil($totalcount/$pagesize);

		//받은메시지
		$start = ($page - 1) * $pagesize;

		//받은메시지
		$sql = "select
					*,
					(SELECT MEMBER_ID from TB_MEMBER where MEMBER_SEQ= BRD_MEMO.rcv_idx) as rcv_id,
			  	(SELECT MEMBER_ID from TB_MEMBER where MEMBER_SEQ= BRD_MEMO.snd_idx) as snd_id
				from BRD_MEMO  where snd_del != 'Y' and snd_idx ='".$session->getString("userno")."' order by snd_dt desc limit $start,$pagesize";
		$list = &$db->queryList($sql);
?>
<?
	if ($list->getLength() == 0)
	{
?>
               <tr>
			<td colspan="6" align="center" height="50"> 보낸 메시지가 없습니다. </td>
		</tr>
<?
	}
	else
	{
		while ($list->hasNext())
		{
			$row 				= & $list->next();
			$memo_idx					= $row->getNumber('memo_idx');
			$snd_idx					= $row->getString('rcv_id');
			$disp_no			= $no;
			$message			= nohtml($row->getString('message'));
			$snd_dt			= $row->getString('snd_dt');
			$cfrm_dt			= $row->getString('cfrm_dt');
?>


				<tr>
					<td><input type="checkbox" id="chkbox[]" name="chkbox[]" title="삭제시체크" value="<?=$memo_idx?>"/></td>
					<td><?=$memo_idx?></td>
					<td class="msgView"><a href="javascript:;" onClick="window.open('memo_view.html?memo_idx=<?=$memo_idx?>','','width=400,height=400,scrollbars=no');"><?=$message?></a></td>
					<td><?=$snd_idx?></td>
					<td><span class="msgtime"><?=$snd_dt?></span></td>
					<td><span class="read"><?if(ereg('0000-00-00',$cfrm_dt)){?><span class="notread">읽지않음</span><?}else{?> 읽음<span class="msgtime">[<?=$cfrm_dt?>]</span><?}?></span></td>
				</tr>
<?
			}
		}
?>

            </table>

            <div class="BtnList">
            	<ul>
                    <li><input type="button" class="btn_del" title="삭제"  onclick="goDelete();"/></li>
                </ul>
            </div>
               </form>
             <div class="pagination">
            	<?$totalpage="10";$pagelistsize=1;?>
            	<? printPageList($page, $totalpage, $pagelistsize, $_SERVER['PHP_SELF'], $basic_param); ?>
            </div>
        </div>
    </div>
</div>

  	<!-- footer start -->
	<? include("../_layout/footer.inc"); ?>
	<!-- footer end -->

</div>
</body>
</html>
